package org.example;

import com.alibaba.fastjson.JSON;
import com.google.protobuf.InvalidProtocolBufferException;
import org.example.proto.UserJavaBean;
import org.example.proto.UserProtoBuf;

import java.util.Arrays;

//学习地址 - https://wkijriqbpn.feishu.cn/drive/folder/IzSQfOJG9lgcdMdV1i4cQ0pinTg
public class MainCompare {
    public static void main(String[] args) {
        // 将数据序列化
        UserProtoBuf.User user = getClientPush();
        byte[] byteData = user.toByteArray();
        System.out.println("获取到PB字节数据：byteData长度=" + byteData.length);
        System.out.println("===========");

        UserJavaBean userJava = new UserJavaBean(18, System.currentTimeMillis(), true, 1.88F, 66.76D, "ZhaoYun", "CH-SC-CD");

        String jsonString = JSON.toJSONString(userJava);
        char[] jsonStringCharArray = jsonString.toCharArray();
        System.out.println("获取到字节数:jsonStringCharArray长度=" + jsonStringCharArray.length);
        System.out.println("获取数据:" + userJava);
        System.out.println("获取数据:" + jsonString);
    }

    /**
     * 模拟
     *
     * @return
     */
    private static UserProtoBuf.User getClientPush() {
        UserProtoBuf.User.Builder user = UserProtoBuf.User.newBuilder();
        user.setAge(18);
        user.setTimestamp(System.currentTimeMillis());
        user.setEnabled(true);
        user.setHeight(1.88F);
        user.setWeight(66.76D);
        user.setUserName("ZhaoYun");
        user.setFullAddress("CH-SC-CD");

        return user.build();
    }
}